package org.batatasframework.support.database.sql.spi;

import org.batatasframework.support.database.AliasNamed;
import org.batatasframework.support.database.metadatas.FieldMetadata;
import org.batatasframework.support.database.metadatas.TableMetadata;
import org.batatasframework.support.database.sql.TableInstance;
import org.batatasframework.support.database.sql.TableRuntimeJoin;
import org.batatasframework.support.database.sql.field.DefaultSelectFragment;
import org.batatasframework.support.database.sql.field.FieldElement;
import org.batatasframework.support.definition.TableDefinitionResource;

/**
 * Clause 子句
 * @author jackson
 *
 */
public interface TableCriterion extends AliasNamed, SelectFragmentCriterion, JoinTableCriterion, QueryFragmentCriterion, SortFragmentCriterion{
	
	TableMetadata getTableMetadata();
	
	TableRuntimeJoin getJoin(TableMetadata tableMetadata)throws Exception;
	
	TableRuntimeJoin newJoin(TableDefinitionResource tableDefinition, TableMetadata tableMetadata)throws Exception;
	
	DefaultSelectFragment field(TableInstance tableSource, FieldMetadata fieldMetadata);
	
	FieldElement loadFieldElement(TableInstance tableSource, FieldMetadata fieldMetadata);
	
	TableInstance safeLoadSource(TableCriterion tableCriterion, TableDefinitionResource tableDefinition, boolean createIfNeed) throws Exception;
}
